package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.aop_whh.annotation.OperateLog;
import com.cskaoyan.wordmemorize.common.constant.ResultCodeEnum;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.UserVocAISituationDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserVocAISituationCommand;
import com.cskaoyan.wordmemorize.service.AIReadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/voc/ai-read")
public class AiReadController_whh {
    @Autowired
    AIReadService aiReadService;
    //场景列表
    @GetMapping("situation/list")
    public Result getSituationList(PageRequest pageRequest) {
        PageDTO<UserVocAISituationDTO> aiSituationList = aiReadService.getAISituationList(pageRequest);
        return Result.ok(aiSituationList);
    }

    //添加阅读
    //有一个疑问，在新增多个选项那里，是如何做到一表更新到另一表的
    @OperateLog(dateType = "等级", operateType = 1)
    @PostMapping("situation")
    public Result postSituation(@RequestBody UserVocAISituationCommand command) {
        aiReadService.addAISituation(command);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @OperateLog(dateType = "等级", operateType = 4)
    @PutMapping("situation")
    public Result putSituation(@RequestBody UserVocAISituationCommand command) {
        aiReadService.updateAISituation(command);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    //删除指定的ai阅读模式
    //好像这个不需要记录在日志里？
    @OperateLog(dateType = "等级", operateType = 2)
    @DeleteMapping("situation/{id}")
    public Result deleteSituation(@PathVariable Long id) {
        aiReadService.deleteAISituation(id);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @OperateLog(dateType = "等级", operateType = 3)
    @DeleteMapping("situation")
    public Result deleteSituationBatch(@RequestBody BatchDeleteCommand command) {

        //将 List<String> ids -> List<Long> ids
        List<String> idsStr = command.getIds();
        List<Long> ids = idsStr.stream()
                .map(Long::valueOf)
                .toList();

        aiReadService.batchDeleteAISituationOption(ids);
        return Result.ok(ResultCodeEnum.SUCCESS);


    }

    @OperateLog(dateType = "等级", operateType = 2)
    @DeleteMapping("option/{id}")
    public Result deleteOption(@PathVariable Long id) {
        aiReadService.deleteAISituationOption(id);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }


}
